package com.xxx.coll;

import java.util.Comparator;
import java.util.Iterator;
import java.util.TreeSet;

/**
 * @version v1.0
 * @Description
 * @Author admin
 * @date 2021/7/21  9:38
 * @Copyright
 */
public class treaSetDome {
    public static void main(String[] args) {
        /*
        * TreeSet:有序，不同步
        * 1.
        * */
       // m1();
        TreeSet treeSet = new TreeSet(new ComparatiirImpl());
        treeSet.add(new worker("毛一",20));
        treeSet.add(new worker("周二",21));
        treeSet.add(new worker("张三",22));
        treeSet.add(new worker("李四",23));
        treeSet.add(new worker("王五",24));


        System.out.println("treeSet = " + treeSet);
        Iterator iterator = treeSet.iterator();
        while (iterator.hasNext()){
            worker worker =(worker) iterator.next();
            System.out.println(worker.getName());
        }

    }

    private static void m1() {
        TreeSet treeSet = new TreeSet();
        treeSet.add(new worker("毛一",20));
        treeSet.add(new worker("周二",21));
        treeSet.add(new worker("张三",22));
        treeSet.add(new worker("李四",22));
        treeSet.add(new worker("王五",22));


        System.out.println("treeSet = " + treeSet);
        Iterator iterator = treeSet.iterator();
        while (iterator.hasNext()){
            worker worker =(worker) iterator.next();
            System.out.println(worker.getName());
        }
    }
}
